﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Claims;
using System.Threading.Tasks;
using Lonewolf.Entity;
using Lonewolf.Infrastructure;
using Lonewolf.IService;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;

namespace Lonewolf.WebApp.Controllers
{
    public class AccountController : AuthController
    {
        private IAdminInfoService adminInfo;
        public AccountController(IAdminInfoService adminInfo)
        {
            this.adminInfo = adminInfo;
        }
        [AllowAnonymous]
        public IActionResult Login()
        {
            return View();
        }
        [AllowAnonymous]
        [HttpPost]
        public async Task<JsonResult<CookieModel>> Login(string loginName, string password)
        {
            string Ip= HttpContext.Connection.RemoteIpAddress.ToString();
            var response = await adminInfo.LoginAsync(loginName,password,Ip);
            if (response.success)
            {
                await SignInAsync(response.Entity);
            }
            return response;
        }
    }
}